%% Setting Directory & Paths
clear
cd /yourpath/FinalReplicationPackage/output/figures/
addpath('/yourpath/FinalReplicationPackage/data/simulations')

alpha_array = [-1:0.1:2]
gamma = 0.484 

for x = 1:length(alpha_array)
    filename = sprintf('alpha=%.1f_gamma=%.3f_weather_largersample.mat', alpha_array(x), gamma);
    load(filename)
    pct_above95_array(x) = aa_pct_above95
    pct_belowours_array(x) = aa_pct_belowours
    rho_eR_mean_array(x) = rho_eR_mean
    rho_eP_mean_array(x) = rho_eP_mean
    rho_dR_mean_array(x) = abs(rho_dR_mean)
    rho_dP_mean_array(x) = rho_dP_mean
    rho_de_mean_array(x) = abs(rho_de_mean)
end

gamma = 0.692 
for x = 1:length(alpha_array)
    filename = sprintf('alpha=%.1f_gamma=%.3f_weather_largersample.mat', alpha_array(x), gamma);
    load(filename)
    pct_above95_array2(x) = aa_pct_above95
    pct_belowours_array2(x) = aa_pct_belowours
    rho_eR_mean_array2(x) = rho_eR_mean
    rho_eP_mean_array2(x) = rho_eP_mean
    rho_dR_mean_array2(x) = abs(rho_dR_mean)
    rho_dP_mean_array2(x) = rho_dP_mean
    rho_de_mean_array2(x) = abs(rho_de_mean)
end

%% Plot 1 (pval < 0.942)
    clf
   
    f = plot(alpha_array, pct_belowours_array, '-o', 'MarkerSize', 10, 'LineWidth', 1.5, color="r");
    hold on
    plot(alpha_array, pct_belowours_array2, '-o', 'MarkerSize', 10, 'LineWidth', 1.5, color='b')
    xlabel("\alpha (Share of action-based persistence)");
    ylabel("Share of cases sargan p-value<0.263");
    %ttl = title("Share of cases sargan p-value<0.263")
    %subtitle(sprintf("(Replication Sample)", gamma))
    lgd = legend('\gamma = 0.484', '\gamma = 0.692', 'Location', 'SouthWest')
    fontsize(lgd,11,'points')
    %fontsize(ttl,12,'points')

    if gamma == 0.692
        ylim([0 1])
    else
        ylim([0 1])
    end
    
    filename = sprintf('sargan_plot_below_ours-bothgammas_largersample.png');
    saveas(f,filename);

%% Plot 2 (pval < 0.05)
    clf
   
    f = plot(alpha_array, pct_above95_array, '-o', 'MarkerSize', 10, 'LineWidth', 1.5, color="r");
    hold on
    plot(alpha_array, pct_above95_array2, '-o', 'MarkerSize', 10, 'LineWidth', 1.5, color="b")
    xlabel("\alpha (Share of action-based persistence)");
    ylabel("Share of cases sargan p-value<0.05");
    %ttl = title("Share of cases sargan p-value<0.05")
    %subtitle(sprintf("(Replication Sample)", gamma))
    lgd = legend('\gamma = 0.484', '\gamma = 0.692', 'Location', 'SouthWest')
    fontsize(lgd,11,'points')
    %fontsize(ttl,12,'points')

    if gamma == 0.692
        ylim([0 1])
    else
        ylim([0 1])
    end
    
    filename = sprintf('sargan_plot_below_pt05-bothgammas_largersample.png');
    saveas(f,filename);

